package com.eightywork.life.activity;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.widget.TextView;

import cn.jpush.android.api.JPushInterface;

import com.eightywork.life.R;
import com.eightywork.life.adapter.ViewImageAdapter;
import com.umeng.analytics.MobclickAgent;

public class ViewImageActivity extends BaseActivity {
	private ViewPager viewPaper;
	private PagerAdapter adapter;
	private List<String> list = new ArrayList<String>();
	private List<String> smallList = new ArrayList<String>();
	private TextView pageText;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.activity_viewimages);
		initView();
		initData();
	}

	private void initView() {
		viewPaper = (ViewPager) findViewById(R.id.text_view_paper);
		pageText = (TextView) findViewById(R.id.textView1);
		adapter = new ViewImageAdapter(this, list, smallList);
		viewPaper.setAdapter(adapter);
		viewPaper.setOnPageChangeListener(new OnPageChangeListener() {
			@Override
			public void onPageSelected(int arg0) {
				pageText.setText((arg0 + 1)+"/"+list.size());
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}
	
	@Override
	public void onResume() {		
		super.onResume();
		JPushInterface.onResume(this);
	    MobclickAgent.onResume(this);
	}
	
	@Override
	public void onPause() {
	    super.onPause();
		JPushInterface.onPause(this);
	    MobclickAgent.onPause(this);
	}


	private void initData() {
		String path = getIntent().getStringExtra("path");
		String smallPath = getIntent().getStringExtra("pathSmall");
		int position = getIntent().getIntExtra("position", 0);		
		if(smallPath!=null){
			String[] smallpaths = smallPath.split(",");
			for (String image : smallpaths) {			
				smallList.add(image);
				adapter.notifyDataSetChanged();
			}
		}
		if (path != null) {
			list.clear();
			String[] paths = path.split(",");
			for (String image : paths) {
				list.add(image);
			}
			pageText.setText("1/"+list.size());
			adapter.notifyDataSetChanged();
			viewPaper.setCurrentItem(position);
		}
		
	}
}
